package com.zc.im.seqsvr.service.impl;

import com.zc.im.seqsvr.domain.MaxSeq;
import com.zc.im.seqsvr.repository.UserSeqRepository;
import com.zc.im.seqsvr.service.MaxSeqService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.annotation.Id;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * Project：im
 * Date：2022/4/13
 * Time：18:51
 * Description：UserSeq service实现类
 *
 * @author Challen.Zhang
 * @version 1.0
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MaxSeqServiceImpl extends AbstractBaseServiceImpl<MaxSeq, Long, UserSeqRepository> implements MaxSeqService {

    @Override
    public Mono<Integer> addStepSize(Long key, Long stepSize) {
        return getDatabaseClient()
                .sql("update im_max_seq set max_seq = max_seq + :stepSize where id = :id")
                .bind("stepSize", stepSize)
                .bind("id", key)
                .fetch()
                .rowsUpdated();
    }
}
